<?php

namespace app\common\listener\notice;

use tmcore\interfaces\ListenerInterface;
use tmcore\services\notice\NoticeService;

/**
 * 发送消息事件
 */
class Msg implements ListenerInterface
{
    public function handle($event)
    {
        try {
            if (empty($event['scene'])) {
                throw new \Exception('场景编码不能为空');
            }

            // 发送通知
            $result = NoticeService::send($event['scene'], $event['params']);
            if (false === $result) {
                throw new \Exception(NoticeService::getError());
            }
            return true;
        } catch (\Exception $e) {
            return $e->getMessage();
        }
    }
}